<?php
/**
 * Plugin Name: Huu Loi_Lấy nội dung
 * Plugin URI: 
 * Description: hiển thị nội dung phù hợp
 * Version: 1.0 
 * Author: Huu Loi
 * Author URI: 
 * License: GPLv2 or later // Thông tin license của plugin, nếu không quan tâm thì bạn cứ để GPLv2 vào đây
 */
?>
<?php

add_action('admin_menu','content_page_action' );
function content_page_action()
{
	//add_submenu_page( 'options-general.php','ContentPage', 'ContentPages', 'ShowContent', "absc", 'get_content_page_admin' );
	add_options_page( 'Lấy nội dung trang', 'Lấy nội dung', 'manage_options', 'get-content-shortcode', 'get_content_page_admin' );
}
function get_content_page_admin()
{
	?>
	 	<div><p>[content_page action=''] lấy nội dung trang web với tham sô action:</p>
			<p>manage-album-images: lấy trang quản lý album</p>
			<p>add-album-images: lấy trang thêm mới album hoặc cập nhập ảnh cho album</p>
			<p>manage-album: lấy trang quản lý album</p> 
		</div> 
	<?php
}

function my_scripts() {
	wp_enqueue_script( 'jquery' );
	wp_register_style( 'custom_jquery', plugins_url('userpage.css', __FILE__) );	
	wp_enqueue_style( 'custom_jquery' );
}
add_action('wp_enqueue_scripts','my_scripts');
function my_styles() {
	wp_register_style( 'custom_style', plugins_url('customstyle.css', __FILE__) );	
	wp_enqueue_style( 'custom_style' );
}
add_action('wp_enqueue_scripts','my_styles');
function my_javascript()
{
	wp_register_script( 'custom_javascript', plugins_url('userpage.js', __FILE__) );
	wp_enqueue_script('custom_javascript');
	wp_localize_script( 'custom_javascript', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),'user_name'=>$_GET['user_name']) );
}
add_action('wp_enqueue_scripts','my_javascript');


function get_content_page($atts)
{ 
	  extract(shortcode_atts(array(
      'action' => "",
   ), $atts));
	?>
	<div class="user_content">
		<?php echo  do_shortcode( "[".$action."]"); ?>
	</div>
<?php
	}
//--------------------------------------------//
$output = ob_get_contents();
ob_end_clean();
add_shortcode("content_page","get_content_page" );
//**********************************************************//
/**
 * hiển thị trang thêm album
 */
function add_album_images()
{?>
	<iframe id="wp_album_manage" src="<?php echo site_url().'/wp-admin/admin.php?page=galleries_bwg';?>" frameborder="0" 
	style="width: 100%; overflow:auto; margin-left: -20px;width:1100px "><?php //remove_menus(); ?></iframe> 
	<!-- <div>
		<?php echo do_shortcode("[create_album]" ); ?>
	</div> -->
<?php
}
add_shortcode("add-album-images","add_album_images" );
/**
 * hiển thị trang quản lý album
 * @return [type] [description]
 */
function manage_album_images()
{?>
	<iframe id="wp_album_manage" src="<?php echo site_url().'/wp-admin/admin.php?page=albums_bwg';?>" frameborder="0" 
			style="width: 100%; overflow:auto;  margin-left: -20px; width:1100px"></iframe>
<?php
}
function remove_menus()
{
global $submenu;

remove_menu_page( 'edit.php' ); // Posts
remove_menu_page( 'upload.php' ); // Media
remove_menu_page( 'link-manager.php' ); // Links
remove_menu_page( 'edit-comments.php' ); // Comments
//remove_menu_page( 'edit.php?post_type=page' ); // Pages
remove_menu_page( 'plugins.php' ); // Plugins
//remove_menu_page( 'themes.php' ); // Appearance
remove_menu_page( 'users.php' ); // Users
remove_menu_page( 'tools.php' ); // Tools
//remove_menu_page(‘options-general.php’); // Settings

remove_submenu_page ( 'index.php', 'update-core.php' );    //Dashboard->Updates
remove_submenu_page ( 'themes.php', 'themes.php' ); // Appearance-->Themes
remove_submenu_page ( 'themes.php', 'widgets.php' ); // Appearance-->Widgets
remove_submenu_page ( 'themes.php', 'theme-editor.php' ); // Appearance-->Editor
remove_submenu_page ( 'options-general.php', 'options-general.php' ); // Settings->General
remove_submenu_page ( 'options-general.php', 'options-writing.php' ); // Settings->writing
remove_submenu_page ( 'options-general.php', 'options-reading.php' ); // Settings->Reading
remove_submenu_page ( 'options-general.php', 'options-discussion.php' ); // Settings->Discussion
remove_submenu_page ( 'options-general.php', 'options-media.php' ); // Settings->Media
remove_submenu_page ( 'options-general.php', 'options-privacy.php' ); // Settings->Privacy
}
add_shortcode("manage-album-images","manage_album_images" );
/**
 * hiển thị trang album của người dùng tương ứng
 * @return [type] [description]
 */

function UserContentHeader()
	{

		require_once(dirname(__FILE__)."\model.php" );
		require_once(dirname(__FILE__)."\controller.php" );
		$model = new UserContentModel();
		$controller = new UserContentController($model);
		$controller->user_header();
		require_once(dirname(__FILE__)."/view.php" );

		$view = new UserContentView($model,$controller);
		$view->display_header();
	}
add_shortcode("user-content-header","UserContentHeader" );


function followers()
	{

		require_once(dirname(__FILE__)."\model.php" );
		require_once(dirname(__FILE__)."\controller.php" );
		$model = new UserContentModel();
		$controller = new UserContentController($model);
		//$controller->user_header();
		require_once(dirname(__FILE__)."/view.php" );

		$view = new UserContentView($model,$controller);
		$view->view_followers_list();
	}
add_shortcode("user-content-followers","followers" );

function following()
	{

		require_once(dirname(__FILE__)."\model.php" );
		require_once(dirname(__FILE__)."\controller.php" );
		$model = new UserContentModel();
		$controller = new UserContentController($model);
		//$controller->user_header();
		require_once(dirname(__FILE__)."/view.php" );

		$view = new UserContentView($model,$controller);
		$view->view_following_list();
	}
add_shortcode("user-content-following","following" );
function images()
	{

		require_once(dirname(__FILE__)."\model.php" );
		require_once(dirname(__FILE__)."\controller.php" );
		$model = new UserContentModel();
		$controller = new UserContentController($model);
		//$controller->user_header();
		require_once(dirname(__FILE__)."/view.php" );

		$view = new UserContentView($model,$controller);
		$view->view_image();
	}
add_shortcode("user-content-images","images" );

add_action( 'wp_ajax_myaction', 'getimagebanner' );
add_action( 'wp_ajax_nopriv_myaction', 'getimagebanner' );
function getimagebanner(){
  	require_once(dirname(__FILE__)."\model.php" );
	require_once(dirname(__FILE__)."\controller.php" );
	$model = new UserContentModel();
	$controller = new UserContentController($model);
	$controller->user_ajax_image_header();
	$view->user_ajax_image_header();
  	wp_die(); // ajax call must die to avoid trailing 0 in your response
}

add_action( 'wp_ajax_follow', 'followclicked' );
add_action( 'wp_ajax_nopriv_follow', 'followclicked' );
function followclicked()
{
	require_once(dirname(__FILE__)."\model.php" );
	require_once(dirname(__FILE__)."\controller.php" );
	$model = new UserContentModel();
	$controller = new UserContentController($model);
	$controller->user_ajax_follow_clicked();
	require_once(dirname(__FILE__)."/view.php" );
	$view=new  UserContentView($model,$controller);
	$view->user_follow();
  	wp_die(); 
}
function cratetable()
{
	 global $wpdb;
	  $bwg_shortcode = "CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . "users_follow` (
	    `follower_id` varchar(255) NOT NULL,
	    `author_id` varchar(255) NOT NULL,
	    CONSTRAINT pk_PersonID PRIMARY KEY (`follower_id`,`author_id`)
	  ) DEFAULT CHARSET=utf8;";

}
register_activation_hook(__FILE__, 'cratetable');
